<script setup lang="ts">
import { ref } from 'vue'
import type { BannerItem } from '@/types/home'
const activeIndex = ref(0)
//当轮播图下标改变时触发
const onChange: UniHelper.SwiperOnChange = (ev) => {
  // console.log(ev.detail?.current)
  // ! 非空断言,主观上排除掉空值情况
  activeIndex.value = ev.detail!.current
}

defineProps<{ list: BannerItem[] }>()
</script>

<template>
  <view class="carousel">
    <swiper :circular="true" @change="onChange" :autoplay="false" :interval="3000">
      <swiper-item v-for="item in list" :key="item.id">
        <navigator url="/pages/index/index" hover-class="none" class="navigator">
          <image mode="aspectFill" class="image" :src="item.imgUrl"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <!-- 指示点 -->
    <view class="indicator">
      <text
        v-for="(item, index) in list.length"
        :key="item"
        class="dot"
        :class="{ active: index === activeIndex }"
      ></text>
    </view>
  </view>
</template>

<style lang="scss">
@import '@/components/styles/XTxSwiper.scss';
</style>
../types/home
